import 'package:ati_package/core/extension/ati_widgets_extension.dart';
import 'package:ati_package/core/routes/app_routes.dart';
import 'package:ati_package/core/utils/ati_color.dart';
import 'package:ati_package/core/utils/ati_font.dart';
import 'package:ati_package/pages/common/ati_scaffold.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../../../core/utils/ati_assets.dart';
import '../../../../core/utils/ati_enum.dart';
import '../../../common/widgets/ati_dialogs.dart';

class UserInfosView extends StatefulWidget {
  const UserInfosView({super.key});

  @override
  State<UserInfosView> createState() => _UserInfosViewState();
}

class _UserInfosViewState extends State<UserInfosView> {
  @override
  Widget build(BuildContext context) {
    return AtiScaffold(
      title: '隐私设置',
      body: ListView(
        children: [
          _buildItem(UserCenterModel.userInfoAvatar, '头像'),
          _buildItem(UserCenterModel.userInfoNickname, '昵称'),
          _buildItem(UserCenterModel.userInfoSignature, '个人签名'),
          _buildItem(UserCenterModel.userInfoGender, '性别'),
          _buildItem(UserCenterModel.userInfoEmail, '邮箱'),
        ],
      ),
    );
  }

  _buildItem(UserCenterModel setModel, String titleStr) {
    return Container(
      height: setModel == UserCenterModel.userInfoAvatar ? 54.r : 46.r,
      margin: EdgeInsets.only(left: 16.r, top: 10.r, right: 16.r),
      padding: EdgeInsets.symmetric(horizontal: 16.r),

      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(8.r),
      ),
      child: Row(
        children: [
          Text(titleStr, style: TextStyle(fontSize: AtiFont.font12)),
          Spacer(),
          ...[
            if (setModel == UserCenterModel.userInfoAvatar)
              CircleAvatar(
                radius: 25.r,
                backgroundColor: AtiColor.pageColor,
                child: CircleAvatar(
                  radius: 22.5.r,
                  backgroundImage: CachedNetworkImageProvider(
                    'https://picsum.photos/800/400?blur',
                  ),
                ),
              ),
            if ((setModel == UserCenterModel.userInfoNickname) |
                (setModel == UserCenterModel.userInfoGender))
              Text(titleStr, style: TextStyle(fontSize: AtiFont.font12)),

            SizedBox(width: 2.r),

            Image.asset(
              width: 16.r,
              height: 16.r,
              AtiAssets.atiNextIcon,
              package: 'ati_package',
            ),
          ],
        ],
      ),
    ).addTapGesture(
      onTap: () {
        switch (setModel) {
          case UserCenterModel.userInfoAvatar:
            {}
            break;
          case UserCenterModel.userInfoNickname:
            {
              Get.toNamed(AtiAppRoutes.userChangeNickName);
            }
            break;
          case UserCenterModel.userInfoSignature:
            {
              Get.toNamed(AtiAppRoutes.userChangeSignature);
            }
            break;
          case UserCenterModel.userInfoGender:
            {
              AtiDialog.bottomListBottomSheet(
                titleStr: '修改性别',
                dataList: ['女', '男', '保密'],
                tapBack: () {},
              );
            }
            break;
          case UserCenterModel.userInfoEmail:
            {
              Get.toNamed(AtiAppRoutes.userChangeEmail);
            }
            break;
          default:
            {
              print('未定义的选项：$setModel');
            }
            break;
        }
      },
    );
  }
}
